﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace ys_dec
{
    class Program
    {
        static void Main(string[] args)
        {
            if (args.Length != 3 || args[0].Length > 2 || (Char.ToUpper(args[0][0]) != 'E' && Char.ToUpper(args[0][0]) != 'D'))
            {
                Console.WriteLine("Format:");
                Console.WriteLine("Decode: d InputPath OutputPath");
                Console.WriteLine("Decode: e InputPath OutputPath");
                return;
            }
            FileStream fsi = File.Open(args[1], FileMode.Open, FileAccess.Read);
            BinaryReader br = new BinaryReader(fsi);
            //1代LZSS封包
            if (Char.ToUpper(args[0][0]) == 'E')
            {
                FileStream fso = File.Open(args[2], FileMode.Create, FileAccess.Write);
                BinaryWriter bw = new BinaryWriter(fso);
                LzssYs lzss = new LzssYs();
                lzss.YsLzss_enc(br, bw);

                bw.Close();
            }

            if (Char.ToUpper(args[0][0]) == 'D')
            {
                //1代LZSS解包
                if (args[0].Length == 1)
                {
                    FileStream fso = File.Open(args[2], FileMode.Create, FileAccess.Write);
                    BinaryWriter bw = new BinaryWriter(fso);
                    LzssYs lzss = new LzssYs();
                    lzss.YsLzss_dec(br, bw);

                    bw.Close();
                }
                //2代ys2解包
                else
                {
                    if (args[0][1] == '2')
                    {
                        ArcYs2 arcfile = new ArcYs2(br,args[2]);
                        arcfile.dec();
                    }
                }
            }
        }

    }
}
